package com.hkccommunity.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonSwitchUtil {

    private static final String JSON_CONTEXT = "application/json;charset=utf-8";

    public static void toJsonSting(HttpServletRequest req, HttpServletResponse resp,Object o) throws ServletException, IOException {
        resp.setContentType(JSON_CONTEXT);
        PrintWriter writer = resp.getWriter();
        String jsonString = JSON.toJSONString(o);
        writer.write(jsonString);
    }

}
